package com.neu.questionnaire_system.controller;


import com.neu.questionnaire_system.beans.ResponseEntity;
import com.neu.questionnaire_system.entity.QuestionHistory;
import com.neu.questionnaire_system.mapper.QuestionnaireMapper;
import com.neu.questionnaire_system.service.impl.QuestionHistoryServiceImpl;
import com.neu.questionnaire_system.util.MethodUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tkj
 * @since 2022-11-13
 */
@CrossOrigin
@RestController
@RequestMapping("/question-history")
public class QuestionHistoryController {

    @Autowired
    QuestionHistoryServiceImpl service;

    //批量插入问卷作答内容
    @RequestMapping("/insertBatchHistory")
    public ResponseEntity saveBatchQuestionHistory(@RequestBody Map<String,Object> map){

        return service.saveBatchQuestionHistory(map.get("qid").toString(),MethodUtil.castList(map.get("list"),QuestionHistory.class));
    }

    //根据问卷id查询各个题目每个答案的作答人数
    @RequestMapping("/selectAllHistoryCountByQid")
    public ResponseEntity selectAllHistoryCountByQid(String qid){
        return service.selectAllHistoryCountByQid(qid);
    }

    //根据问卷id获取全部问题作答记录，具体每题的每个答案作答人是谁
    @RequestMapping("/selectAllHistoryByQid")
    public ResponseEntity selectAllHistoryByQid(String qid){
        return service.selectAllHistoryByQid(qid);
    }

}
